 //
//  BaseViewController.m
//  SmartCoin
//
//  Created by apple on 2018/3/7.
//  Copyright © 2018年 Cynic. All rights reserved.
//

#import "BaseViewController.h"

@interface BaseViewController ()

@end

@implementation BaseViewController

-(instancetype)init{
    self = [super init];
    self.automaticallyAdjustsScrollViewInsets = NO;
    [self loadXPart];
    return self;
}

-(instancetype)initInChildWithFrame:(CGRect)frame{
    self = [super init];
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.view.frame = frame;
//    self.view.backgroundColor = [UIColor purpleColor];
//    [self loadXPart];
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
}

#pragma mark--design navigationview
//自定义navigationview centertitle popbtn rightoperationbtn
-(void)setNavigationViewWithTitle:(NSString *)navigationTitle WithCanPop:(BOOL)canPop WithPopData:(NSString *)leftData WithPopisString:(BOOL)leftisString WithHasRightOperation:(BOOL)hasRightOperation WithrightOperationData:(NSString *)rightData WithRightisString:(BOOL)rightisString WithNavigationColor:(UIColor *)navigationColor withBgView:(UIView *)bgview{
    CGFloat topmove = cxsingler.topdis;
    CGFloat topdis = 0;
    if (!_navigationView) {
        _navigationView = [[UIView alloc]initWithFrame:CGRectMake(0, 0 + topmove -  cxsingler.navitop, cx_wid, 44 +  cxsingler.navitop)];
        _navigationView.backgroundColor = navigationColor;
    }
    if (canPop) {//有左侧按钮 poptaed:默认navigation pop
        _popButton = [[UIButton alloc]initWithFrame:CGRectMake(0,  cxsingler.navitop, 44, 44)];
        if (leftisString) {
            [_popButton setTitle:leftData forState:UIControlStateNormal];
        }
        else{
            [_popButton setImage:[UIImage imageNamed:leftData] forState:UIControlStateNormal];
        }
        [_popButton addTarget:self action:@selector(popTaped:) forControlEvents:UIControlEventTouchUpInside];
        [_navigationView addSubview:_popButton];
    }
    
    if (hasRightOperation) {//有右侧按钮 rightTped:
        _rightOperationButton = [[UIButton alloc]initWithFrame:CGRectMake(cx_wid - 44,  cxsingler.navitop, 44, 44)];
        _rightOperationButton.titleLabel.font = [UIFont systemFontOfSize:18];
        if (rightisString) {
            [_rightOperationButton setTitle:rightData forState:UIControlStateNormal];
        }
        else{
            [_rightOperationButton setImage:[UIImage imageNamed:rightData] forState:UIControlStateNormal];
        }
        [_rightOperationButton addTarget:self action:@selector(rightTped:) forControlEvents:UIControlEventTouchUpInside];
        [_navigationView addSubview:_rightOperationButton];
    }
    if (![navigationTitle isKindOfClass:[NSNull class]]) {//有navigation标题 centertitle
        _centerTitle = [[UILabel alloc]init];
        _centerTitle.bounds = CGRectMake(0,  0, cx_wid - 88 - 40, 20);
        _centerTitle.center = CGPointMake(cx_wid / 2, 22 +  cxsingler.navitop);
        _centerTitle.textAlignment = NSTextAlignmentCenter;
        _centerTitle.text = navigationTitle;
        _centerTitle.font = [UIFont systemFontOfSize:18];
        _centerTitle.textColor = [UIColor whiteColor];
        [_navigationView addSubview:_centerTitle];
    }
    
    [bgview addSubview:_navigationView];
}

#pragma mark--right navigationitem taped
-(void)rightTped:(UIButton *)sender{
    [self.view endEditing:YES];
}

#pragma mark--poptaped
-(void)popTaped:(UIButton *)sender{
    [self.view endEditing:YES];
    [self.navigationController popViewControllerAnimated:YES];
}





-(CGFloat)getrealHit:(CGFloat)placeheight{//比例计算对应设备高度
    return placeheight / 667 * cx_hit;
}


-(id)Nnll:(id)olpart withPlace:(id)place{//空替换为place
    if ([olpart isKindOfClass:[NSNumber class]]) {
        return [NSString stringWithFormat:@"%@",olpart];
    }

    if ([olpart isKindOfClass:[NSNull class]] || olpart == nil || [olpart length] == 0) {
        return place;
    }
    return olpart;
}

-(NSString *)gettimeByInter:(NSInteger)timeinter{//时间戳转换为nsstring date
    NSString *str = [NSString stringWithFormat:@"%ld",timeinter];
    long timeint = timeinter;
    if (str.length == 13) {
        timeint = timeinter / 1000;//毫秒级 切换为秒级
    }
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateStyle:NSDateFormatterMediumStyle];
    [formatter setTimeStyle:NSDateFormatterShortStyle];
    [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSDate *createtime = [NSDate dateWithTimeIntervalSince1970:timeint];
    NSString *timestr = [formatter stringFromDate:createtime];
    return timestr;
}

-(void)loadXPart{//布局iphonex顶部底部部分
    if ([self.parentViewController isKindOfClass:[BaseViewController class]]) {
        return;
    }
    if (cxsingler.topdis > 20) {
        UIView *bg = [[UIView alloc] initWithFrame:self.view.frame];//总背景
        UIView *topbg = [[UIView alloc] initWithFrame:CGRectMake(0, 0, cx_wid, cxsingler.topdis)];//顶部部分
        UIView *bottombg = [[UIView alloc] initWithFrame:CGRectMake(0, cx_hit - cxsingler.bottomdis, cx_wid, cxsingler.bottomdis)];//底部部分
        bottombg.backgroundColor = bggrayColor;
        for (NSInteger index = 0; index < 1; index ++) {
            CAGradientLayer *layer = [CAGradientLayer layer];
            
            layer.colors = @[(id)[CXSinglerModel colorWithHex:@"#FF7F5A" alpha:1].CGColor,(id)[CXSinglerModel colorWithHex:@"#FE4438" alpha:1].CGColor];
            layer.startPoint = CGPointMake(0, 0);
            layer.endPoint = CGPointMake(1, 0);
//            [enterBtn.layer addSublayer:layer];
            if (index == 0) {
                layer.frame = topbg.bounds;
                [topbg.layer addSublayer:layer];
            }
            else{
                 layer.frame = bottombg.bounds;
                [bottombg.layer addSublayer:layer];
            }
        }
        UIBlurEffect * blur = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];//毛玻璃
        UIVisualEffectView * effe = [[UIVisualEffectView alloc]initWithEffect:blur];
        effe.frame = topbg.frame;
        effe.layer.masksToBounds = YES;
        effe.alpha = 0.4;
        UIBlurEffect * secblur = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
        UIVisualEffectView * seceffe = [[UIVisualEffectView alloc]initWithEffect:secblur];
        seceffe.frame = topbg.frame;
        seceffe.layer.masksToBounds = YES;
        seceffe.layer.cornerRadius = 0;
        seceffe.alpha = 0.4;
//        [topbg addSubview:effe];
        [self.view addSubview:bg];
        [bg addSubview:topbg];
//        [bottombg addSubview:seceffe];
        [bg addSubview:bottombg];
        [bg sendSubviewToBack:topbg];
        [bg sendSubviewToBack:bottombg];
        [self.view sendSubviewToBack:bg];
    }
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}





@end
